package com.right.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.right.dao.FoodsDao;
import com.right.dao.StoreDao;
import com.right.dao.impl.FoodsDaoImpl;
import com.right.dao.impl.StoreDaoImpl;
import com.right.entity.Foods;
import com.right.entity.Store;
import com.right.service.FoodsService;
import com.right.service.StoreService;
import com.right.service.impl.FoodsServiceImpl;
import com.right.service.impl.StoreServiceImpl;

/**
 * Servlet implementation class MainServlet
 */
@WebServlet("/MainServlet")
public class MainServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	StoreService storeService = new StoreServiceImpl();
	FoodsService foodsService = new FoodsServiceImpl();
	FoodsDao foodsDao = new FoodsDaoImpl();
	List<Foods> list2 = null;
	
    /**
     * @see HttpServlet#HttpServlet()
     */
    public MainServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String op = "";
		if (request.getParameter("op")!=null) {
			op = request.getParameter("op");
		}if ("".equals(op)) {
			List<Store> list1 =  storeService.getStroe();
				
				 list2 = foodsDao.getFoodsByStore(list1.get(0).getStore());
				 System.out.println("list2"+list2);
			request.setAttribute("list1", list1);
			request.setAttribute("list2", list2);
			request.getRequestDispatcher("main.jsp").forward(request, response);
			
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
